package com.wrial.simple;
/*
 * @Author  Wrial
 * @Date Created in 22:30 2020/3/23
 * @Description  167
   返回的下标值（index1 < index2）不是从零开始的。
    你可以假设每个输入只对应唯一的答案，而且你不可以重复使用相同的元素。
 */

import java.util.HashMap;

public class LeetCode_167 {

    public static void main(String[] args) {
        int[] nums = {7,2, 11, 15};
        LeetCode_167 twoNumsSum = new LeetCode_167();
        int[] ints = twoNumsSum.twoSum(nums, 9);
        for (int anInt : ints) {
            System.out.println(anInt);
        }
    }


    public int[] twoSum(int[] numbers, int target) {

        HashMap<Integer, Integer> map = new HashMap<>();

        for (int i = 0; i < numbers.length; i++) {
            int temp = target - numbers[i];
            if (map.containsKey(temp)) {
                return new int[]{map.get(temp)+1,i+1};
            }
            map.put(numbers[i], i);
        }
        return null;

    }
}
